package com.ebelter.btcomlib.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ebelter.btcomlib.R;
import com.ebelter.btcomlib.utils.ViewUtils;


/**
 * 组合控件8 不知道怎么起名字了 还是按序号来吧
 */

public class CombinView8 extends LinearLayout{
    public CombinView8(Context context) {
        this(context,null);
    }


    public CombinView8(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }


    public CombinView8(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CombinView8);
        if (typedArray != null) {
            title1 = typedArray.getString(R.styleable.CombinView8_title1);
            title2 = typedArray.getString(R.styleable.CombinView8_title2);
            title3 = typedArray.getString(R.styleable.CombinView8_title3);
            title4 = typedArray.getString(R.styleable.CombinView8_title4);
            title5 = typedArray.getString(R.styleable.CombinView8_title5);
            src = typedArray.getDrawable(R.styleable.CombinView8_src);
            typedArray.recycle();
        }

        initView(getContext());

        initDatas();

    }

    private void initDatas() {
        textView1.setText(title1);
        textView2.setText(title2);
        textView3.setText(title3);
        textView4.setText(title4);
        textView5.setText(title5);
        imageView.setImageDrawable(src);
    }

    public void setTitle(int index,String title){
        if (index==1){
            ViewUtils.setTextViewStr(textView1,title);
        }else if (index==2){
            ViewUtils.setTextViewStr(textView2,title);
        }else if (index==3){
            ViewUtils.setTextViewStr(textView3,title);
        }else if (index==4){
            ViewUtils.setTextViewStr(textView4,title);
        }else if (index==5){
            ViewUtils.setTextViewStr(textView5,title);
        }
    }



    public void setImaSrc(int res){
        if (imageView!=null) imageView.setImageResource(res);
    }


    private String title1;
    private String title2;
    private String title3;
    private String title4;
    private String title5;
    private Drawable src;

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    private TextView textView5;
    private View cb5_t5_hl;
    private ImageView imageView;


    private LinearLayout root;



    public void setTitle5Display(boolean display){
        if (display){
            ViewUtils.displayView(textView5);
            ViewUtils.displayView(cb5_t5_hl);
        }else {
            ViewUtils.goneView(textView5);
            ViewUtils.goneView(cb5_t5_hl);
        }
    }

    private void initView(Context context) {
        View view =  View.inflate(context, R.layout.cb8_layout, this);//把那个布局当做是自己的孩子
        root = view.findViewById(R.id.cb8_root_ll);
        textView1=view.findViewById(R.id.cb8_title1);
        textView2=view.findViewById(R.id.cb8_title2);
        textView3=view.findViewById(R.id.cb8_title3);
        textView4=view.findViewById(R.id.cb8_title4);
        textView5=view.findViewById(R.id.cb8_title5);
        cb5_t5_hl=view.findViewById(R.id.cb5_t5_hl);
        imageView=view.findViewById(R.id.cb8_iv);

    }

    public void setTitleSize(int index,int sp){
        if (index==1){
            ViewUtils.setTextSize(textView1,sp);
        }else if (index==2){
            ViewUtils.setTextSize(textView2,sp);
        }else if (index==3){
            ViewUtils.setTextSize(textView3,sp);
        }else if (index==4){
            ViewUtils.setTextSize(textView4,sp);
        }else if (index==5){
            ViewUtils.setTextSize(textView5,sp);
        }
    }

    public void setTitleSizes(int sp) {
        ViewUtils.setTextSize(textView1,sp);
        ViewUtils.setTextSize(textView2,sp);
        ViewUtils.setTextSize(textView3,sp);
        ViewUtils.setTextSize(textView4,sp);
        ViewUtils.setTextSize(textView5,sp);
    }
}
